package com.twu.biblioteca;


import com.twu.biblioteca.services.BookService;
import com.twu.biblioteca.services.LoginService;
import com.twu.biblioteca.services.MovieService;
import com.twu.biblioteca.services.UserService;
import com.twu.biblioteca.resources.Menu;
import java.util.*;

public class BibliotecaApp {

    private static final String WELCOME_MESSAGE="Welcome to Biblioteca - Library Management System";
    private static Session session;

    public  BibliotecaApp()
    {
        Session session=new Session();
        setSession(session);
    }
    public String getWelcomeMessage()
    {
        return WELCOME_MESSAGE;
    }

    public static Session getSession()
    {
        return session;
    }

    private void setSession(Session session) {
        this.session = session;
    }

    public static void main(String[] args) {

        BibliotecaApp appInstance=new BibliotecaApp();
        
        System.out.println(appInstance.getWelcomeMessage());

        appInstance.initiateBiblioteca();

    }

    private void initiateBiblioteca() {

        Scanner getChoice=new Scanner(System.in);
        int choice=0;
        while(choice!=-1)
        {
            System.out.println("Menu");
            String menuList=Menu.getInstance().displayMenu(getSession());
            System.out.println(menuList);
            System.out.println("Enter Choice (-1 to terminate) :");
            choice=getChoice.nextInt();
            if(choice!=-1) {
                switch (choice) {
                    case 1:
                        BookService bookService = new BookService();
                        String booksDetails = bookService.getBooksDetail();
                        System.out.println(booksDetails);
                        break;
                    case 2:
                        if(getSession().isLoginStatus())
                        {
                        BookService bookServiceInstance = new BookService();
                        bookServiceInstance.initiateBookService();
                        }
                        else
                        {
                            System.out.println(LoginService.getLoginMessage());
                        }
                            break;
                    case 3:
                        if(getSession().isLoginStatus())
                        {
                        UserService userServiceInstance = new UserService();
                        String membershipResponse=userServiceInstance.viewMembershipDetails();
                        System.out.println(membershipResponse);
                        }
                        else
                        {
                            System.out.println("Please talk to a Librarian. Thank you.");
                        }
                        break;
                    case 4:
                        MovieService movieServiceInstance = new MovieService();
                        String moviesDetails = movieServiceInstance.viewMovieDetails();
                        System.out.println(moviesDetails);
                        break;
                    case 5:
                         LoginService loginService = new LoginService();
                        String loginResponse = loginService.initiateLogin();
                        System.out.println(loginResponse);
                        break;
                      default:
                          System.out.println("Select a valid option!!");
                  }
            }
        }
    }



}
